var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo:null,
        ranking: null,
        school: null,
        imgUrl:null  
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
           userId: options.userId,
           number: options.number,
           datatime: options.datatime,
           schoolid: options.schoolid
        }) 
        var that = this;
        wx.request({
            url: 'https://woxiaoshitang.com/activity/health.php/applet/getranking',
            method: "POST",
            data: {
                schoolid: that.data.schoolid,
                datatime: that.data.datatime
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            success: function (res) {
                that.setData({
                    ranking: res.data.ranking,
                    school: res.data.school,
                    imgUrl: "https://woxiaoshitang.com/activity/Public/upload/Wx/" + res.data.school.image
                })
                var rank = res.data.ranking;
                var rankArr = [];
                var usersId = that.data.userId
                for(var i = 0; i < rank.length; i++ ){
                    rankArr.push(rank[i].userid);
                }
                var userIndex = null;
                for (var j = 0; j < rankArr.length; j++){
                   var index = j;
                   if (rankArr[index] == usersId){
                      userIndex = index;
                   }
                }
                that.setData({
                    userIndex: userIndex
                })
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        // wx.showNavigationBarLoading() //在标题栏中显示加载
        console.log("%c 000000000000","background:#000;color:#0ff")
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})